package crp.core.faculty.domain.models;

import com.qwlabs.auditing.AuditedEntity;
import crp.core.department.domain.models.DepartmentEntity;
import crp.core.shared.Tables;
import lombok.Getter;
import lombok.Setter;
import org.hibernate.annotations.GenericGenerator;

import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import java.util.Optional;

@Getter
@Setter
@Entity
@Table(name = Tables.FACULTY_DEPARTMENT)
public class FacultyDepartmentEntity extends AuditedEntity {
    @Id
    @GeneratedValue(generator = "UUID")
    @GenericGenerator(name = "UUID", strategy = "org.hibernate.id.UUIDGenerator")
    private String id;
    @ManyToOne(fetch = FetchType.LAZY)
    private FacultyEntity faculty;
    @ManyToOne(fetch = FetchType.LAZY)
    private DepartmentEntity department;

    public String getFacultyId() {
        return Optional.ofNullable(faculty).map(FacultyEntity::getId).orElse(null);
    }
}
